input=imread('Cap_50_4.2501.bmp','bmp');
%input=input'/255;

lz=15;
lx=200;
ly=50;
res=64;   %RESERVIOR LENGTH
starting_point=500;

ino=1-input(1+starting_point:lx+starting_point,1:ly,2)/255;

a=zeros(lx+res,ly+2);

for i=1:lx
    for j=1:ly+2
        if ((j==1) || (j==ly+2))
            a(i,j)=1;
        else
            a(i,j)=ino(i,j-1);
        end
        
    end
end





 fid = fopen('rough_capillary.vtk','wt');
fprintf(fid,'# vtk DataFile Version 2.0\n');
fprintf(fid,'J.Yang Lattice Boltzmann Simulation 3D Capillary Trapping\n');
fprintf(fid,'ASCII\n');
fprintf(fid,'DATASET STRUCTURED_POINTS\n');
fprintf(fid,'DIMENSIONS         %i         %i         %i\n',lx+res,ly+2,lz);
fprintf(fid,'ORIGIN 0 0 0\n');
fprintf(fid,'SPACING 1 1 1\n');
fprintf(fid,'POINT_DATA     %i\n',(lx+res)*(ly+2)*lz);
fprintf(fid,'SCALARS sample_scalars float\n');
fprintf(fid,'LOOKUP_TABLE default\n');     

 for k=1:lz
     for j=1:ly+2
         for i=1:lx+res
             
         if ((k==1) ||(k==lz)) && (i<=lx)
             fprintf(fid,'%1d\n',1);
         else
             fprintf(fid,'%1d\n',a(i,j));
         end
         
         end
     end
 end
 
 lx+res
 ly+2
 lz
 
